package cn.itlaobing.dao.ResultSetHandler;

import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 类名: cn.itlaobing.dao.ResultSetHandler
 * 功能:
 * 作者: 王博
 * 日期: 2017/11/14 16:29
 */
public class GoodResultSerHandler implements ResultSetHandler<List<Map<String, Object>>> {
        @Override
        public List<Map<String, Object>> handle(ResultSet rs) throws SQLException {
            List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
            while (rs.next()) {
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("id", rs.getObject(1));
                map.put("goodName", rs.getObject(2));
                map.put("price", rs.getObject(3));
                map.put("picUrl", rs.getObject(4));
                mapList.add(map);
            }
            return mapList.size() == 0 ? null : mapList;
        }
}
